package com.pencilisland.pay.app.mp.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.pencilisland.pay.api.bean.mp.app.MessageRequest;
import com.pencilisland.pay.api.bean.mp.app.MessageResponse;
import com.pencilisland.pay.api.bean.mp.app.SendWxTemplateREQ;
import com.pencilisland.pay.api.bean.mp.app.SendWxTemplateRES;
import com.pencilisland.pay.api.bean.mp.core.WxTemplateREQ;
import com.pencilisland.pay.api.bean.mp.core.WxTemplateRES;
import com.pencilisland.pay.app.mp.service.MBService;
/**
* 报文逻辑处理.发送微信模板消息
*
* @author breeze
*/
import com.pencilisland.pay.app.service.RestService;
@Service("MB_sendWxTemplate")
public class  SendWxTemplateMB implements MBService {

	@Autowired
	ObjectMapper objectMapper;
	@Autowired
	RestService restService;
	

	@Override
	public MessageResponse process(MessageRequest request) {
		SendWxTemplateREQ requestBean = getRequestBody(request);
		
		WxTemplateREQ wxTemplateReq = new WxTemplateREQ();
		wxTemplateReq.setOrderNo(requestBean.getOrderNo());
		wxTemplateReq.setFormId(requestBean.getFormId());
		
		restService.sendToCoreMP("wxTemplate", wxTemplateReq, WxTemplateRES.class);
		
		SendWxTemplateRES res= new SendWxTemplateRES(true,null,"OK");
		return res;
	}
	
	public SendWxTemplateREQ getRequestBody(MessageRequest request){
		return objectMapper.convertValue(request.getBody(), SendWxTemplateREQ.class);
	}

}
